﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine.Plot;
using ExcelLibrary.SpreadSheet;

namespace ResearchDemonstration.Export
{
    /// <summary>
    /// Export data analized with <typeparamref name="Engine.DataAnalizator"/> to exel file
    /// </summary>    
    public class DataAnalizeExelReport
    {
        public DataAnalizeExelReport() 
        { 
        
        }

        /// <summary>
        /// This method is export to exel file.
        /// !!TODO - need some changes for long running export operations. 
        /// </summary>
        /// <param name="filePath">Full path to export file</param>
        public void ExportToExelFile(string filePath, IList<PlotPoint> data) 
        {
            Workbook report = new Workbook();
            Worksheet worksheet = new Worksheet("результаты исследований");
            worksheet.Cells[0, 0] = new Cell("Lattice Id");
            worksheet.Cells[0, 1] = new Cell("X");
            worksheet.Cells[0, 2] = new Cell("Conductance");
            worksheet.Cells[0, 3] = new Cell("Type");
            worksheet.Cells[0, 4] = new Cell("Element Conductance");
            
            for (var i = 1; i <= data.Count; i++ ) {
                worksheet.Cells[i, 0] = new Cell(data[i - 1].LatticeId);
                worksheet.Cells[i, 1] = new Cell(data[i - 1].X);
                worksheet.Cells[i, 2] = new Cell(data[i - 1].Conductance);
                worksheet.Cells[i, 3] = new Cell(data[i - 1].Type);
                worksheet.Cells[i, 4] = new Cell(data[i - 1].ElementConductance);
            }
            report.Worksheets.Add(worksheet);
            report.Save(filePath);
        }
   
    }
}
